﻿using System.Collections;
using System.Collections.Generic;
using System.Text;
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using System.Data;



public class Passive : MonoBehaviour
{
    private string result;

    [SerializeField]
    private string formula;
    private float modifier;
    [SerializeField]
    private Text passive;

    StringBuilder pre = new StringBuilder();
    StringBuilder post = new StringBuilder();
    StringBuilder postPost = new StringBuilder();
    int test = 0;
    private int xCount;
    DataTable dt = new DataTable();

    private void Start()
    {

        int counter = 0;
        while (counter < formula.Length)
        {
            if (formula[counter] != 'x')
            {
                pre.Append(formula[counter]);
            }
            else
            {
                xCount++;
                break;
            }
            counter++;
        }
        counter++;
       
        while (counter < formula.Length)
        {
            if (formula[counter] != 'x')
            {
                post.Append(formula[counter]);
            }
            else
            {
                xCount++;
                break;
            }
            counter++;


        }

        counter++;
      
        while (counter < formula.Length) 
        {
            postPost.Append(formula[counter]);
            counter++;
        }

        
    }


    public void Calculate(int secondaryStart)
    {
        if (xCount > 1)
        {
            result = pre + secondaryStart.ToString() + post + secondaryStart.ToString() +postPost;
        }
        else
        {
            result = pre + secondaryStart.ToString() + post;
           
        }
        var tmpRes = dt.Compute(result,"");
        
        modifier = float.Parse(tmpRes.ToString());
  
        modifier = Mathf.Round(modifier*100f)/100;

        passive.text = modifier.ToString();
        
    }
}